package sdk.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sdk.service.ContractManager;
import sdk.service.DutyManager;

import lgq.service.CourseManager;
import lgq.service.EmpManager;
import lgq.service.TeacherManager;
import lgq.service.TrainManager;
import lgq.service.TrainPropertyManager;
import lgq.service.TrainTypeManager;
import lgq.service.TrainWayManager;
import model.Contract;
import model.Course;
import model.Dept;
import model.Duty;
import model.Emp;
import model.EmpTransfer;
import model.Teacher;
import model.Train;
import model.TrainCourse;
import zym.service.TansferMag;
import dao.DeptDAO;
import dao.DutyDAO;
import dao.EmpDAO;
import dao.impl.DeptDAOImpl;
import dao.impl.DutyDAOImpl;
import dao.impl.EmpDAOImpl;

public class AddContractServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
		Contract contract =new Contract();
		
		contract.setContractno(request.getParameter("Contractno"));
		
		EmpManager em = new EmpManager();
		contract.setEmp(em.getById(Integer.parseInt(request.getParameter("empid"))));
		
		String duty[] = request.getParameterValues("duty");
		List <Duty> list=new ArrayList<Duty>();
		for(int i=0;i<duty.length;i++)
		{
			DutyManager dum = new DutyManager();
			Duty d = new Duty();
			d = new DutyManager().getDutyById(Integer.parseInt(duty[i]));
			list.add(d);
		}
		
		try {
			contract.setStarttime(new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("starttime")));
			contract.setEndtime(new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("endtime")));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		contract.setContent(request.getParameter("content"));
		contract.setSupplement(request.getParameter("supplement"));
		
	}

}
